﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using WebAppMVCTest01.Models;
//Test01.7.7.1 添加对数据访问层的 Using
using WebAppMVCTest01.DataAccessLayer;

namespace WebAppMVCTest01.ViewModels
{
	/// <summary>业务逻辑层</summary>
	public class EmployeeBusinessLayer
	{
		public List<Employee> GetEmployees()
		{
			List<Employee> employees = new List<Employee>();
			Employee emp = new Employee()
			{
				FirstName = "Johnson",
				LastName = "Fernandes",
				Salary = 14000
			};
			employees.Add(emp);

			emp = new Employee()
			{
				FirstName = "Michael",
				LastName = "Jackson",
				Salary = 16000
			};
			employees.Add(emp);

			emp = new Employee()
			{
				FirstName = "Robert",
				LastName = "Pattinson",
				Salary = 20000
			};
			employees.Add(emp);

			return employees;
		}

		//Test01.7.7.2 添加 GetEFEmployees() 方法, 调用数据访问层, 获取需要的数据
		/// <summary>通过数据访问层 SalesEPRDAL 从数据库获取数据</summary>
		/// <returns></returns>
		public List<EFEmployee> GetEFEmployees()
		{
			SalesEPRDAL salesDal = new SalesEPRDAL();
			return salesDal.EFEmployees.ToList();
		}

		//保存新数据到数据库
		/// <summary>通过数据访问层 SalesEPRDAL 将数据存入数据库</summary>
		/// <param name="efEmp">要保存的数据</param>
		/// <returns></returns>
		public EFEmployee SaveEmployee(EFEmployee efEmp)
		{
			SalesEPRDAL salesDal = new SalesEPRDAL();
			salesDal.EFEmployees.Add(efEmp);
			salesDal.SaveChanges();
			return efEmp;
		}
	}
}